/*
Copyright (c) [2022] [shawnping]
[masm-assistant] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2. 
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2 
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
See the Mulan PSL v2 for more details.
*/

/*                ███╗   ███╗ █████╗ ███████╗███╗   ███╗                    */
/*                ████╗ ████║██╔══██╗██╔════╝████╗ ████║                    */
/*                ██╔████╔██║███████║███████╗██╔████╔██║                    */
/*                ██║╚██╔╝██║██╔══██║╚════██║██║╚██╔╝██║                    */
/*                ██║ ╚═╝ ██║██║  ██║███████║██║ ╚═╝ ██║                    */
/*                ╚═╝     ╚═╝╚═╝  ╚═╝╚══════╝╚═╝     ╚═╝                    */
/*                                                                          */
/*   █████╗ ███████╗███████╗██╗███████╗████████╗ █████╗ ███╗   ██╗████████╗ */
/*  ██╔══██╗██╔════╝██╔════╝██║██╔════╝╚══██╔══╝██╔══██╗████╗  ██║╚══██╔══╝ */
/*  ███████║███████╗███████╗██║███████╗   ██║   ███████║██╔██╗ ██║   ██║    */
/*  ██╔══██║╚════██║╚════██║██║╚════██║   ██║   ██╔══██║██║╚██╗██║   ██║    */
/*  ██║  ██║███████║███████║██║███████║   ██║   ██║  ██║██║ ╚████║   ██║    */
/*  ╚═╝  ╚═╝╚══════╝╚══════╝╚═╝╚══════╝   ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝    */

/* eslint-disable @typescript-eslint/naming-convention */

import { directives } from './Keywords/reservedWords_directives';
import { instructions } from './Keywords/reservedWords_Instructions';
import { register } from './Keywords/reservedWrods_registers';
import { selector, reservedWordsUpper, instanceOfIRservedWord, instanceOfIDirectiveWE, reservedWordToCompletion } from './Base/baseInterfaceFile';
import * as vscode from 'vscode';
import * as config from './configuration';

const rwGroup = reservedWordsUpper(directives, register, instructions);

const rwCompItemUpper = reservedWordToCompletion(rwGroup.upper);
const rwCompItem = reservedWordToCompletion(rwGroup.lower);




//指令与伪指令Completion
export const compDirIns = vscode.languages.registerCompletionItemProvider(selector, {
    provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext) {
        let linePrefix = document.lineAt(position).text.substring(0, position.character);
        if (linePrefix.match(/\W+$/i) !== null) {
            if (config.isUpperMode) {
                for (let i = 0; i < rwCompItemUpper.headNoWord.length; i++) {
                    if (linePrefix.endsWith(rwCompItemUpper.headNoWord[i].trigger)) {
                        return rwCompItemUpper.headNoWord[i].comList;
                    }
                }
            }
            else {
                for (let i = 0; i < rwCompItem.headNoWord.length; i++) {
                    if (linePrefix.endsWith(rwCompItem.headNoWord[i].trigger)) {
                        return rwCompItem.headNoWord[i].comList;
                    }
                }
            }
        }
        else {
            if (config.isUpperMode) {
                return rwCompItemUpper.headWord;
            }
            else {
                return rwCompItem.headWord;
            }
        }
        return undefined;
    }
}, '@', '_', '$', '?', '.');

export const compDirInsPara = vscode.languages.registerCompletionItemProvider(selector, {
    provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext) {
        let linePrefix = document.lineAt(position).text.substring(0, position.character);

        return [];
    }
},'[',':','.',',',' ','<');